﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client.model
{
    public class ControlPoint : INotifyPropertyChanged
    {
        int x;
        int y;
        int width = 8;
        int height = 8;
        int ySlide;
        int y0;
        int yMax;
        float screenHeight;
     
        bool isCapsized;
      
        public static int graphHeight = 300;

        public static int step = 2;       

        public ControlPoint(int x, int y)
        {
            X = x - width / 2;
            Y =  y;
        }

        public ControlPoint(int x, int y, int yMax, int screenHeight, bool isCapsized)
        {
            this.isCapsized = isCapsized;
            this.screenHeight = screenHeight;
            this.yMax = yMax;
            X = x - width / 2;
            Y = y;
        }    

        public bool within(int a, int b)
        {
            a -= width / 2;
            b -= height / 2;
            if (a >= x - width / 2 &&
                b >= y - height / 2 &&
                a <= x + width / 2 &&
                b <= y + height / 2)
                return true;
            else
                return false;
        }

        public int X
        {
            get { return x; }
            set { x = value; NotifyPropertyChanged("X"); }
        }

        public int Y
        {
            get { return y; }
            set { 
                y = value;

                if (isCapsized) Y0 = (int)(y * ((float)screenHeight / yMax));
                else Y0 = graphHeight - (y - 40 + ySlide) * 4; // *4로 확대

                NotifyPropertyChanged("Y"); 
            }
        }

        public int Width
        {
            get { return width; }
            set { width = value; }
        }

        public int Height
        {
            get { return height; }
            set { height = value; }
        }    

        public int YSlide
        {
            get { return ySlide; }
            set { ySlide = value; Y = y;                
            }
        }

        public int Y0
        {
            get { return y0 - height / 2; }
            set { 
                y0 = value;
                if (y0 < 0) Y0 = 0;
               
                NotifyPropertyChanged("Y0"); }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
